/*
 * 
 * 
 */
package com.pclong.net;

import java.net.*;
import java.io.*;
import java.util.logging.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

/**
 *@date 2011-11-7,22:07:38
 * @author long
 * @email 405409357@qq.com
 * @description SingleServer类
 */
public class SingleServer extends Thread {

    private static final Logger logger = LogManager.getLogger(SingleServer.class);
    private ServerSocket ss;
    private Socket socket;
    private BufferedReader in;
    private PrintWriter out;

    public SingleServer() {
          start();
    }

    @Override
    public void run() {
        try {
            ss = new ServerSocket(10000);
            int count = 0;
            while (count <3) {
                count++;
                socket = ss.accept();
                in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                out = new PrintWriter(socket.getOutputStream());
                String line = in.readLine();
                out.println("your input:" + line);
                logger.debug("your input:" + line);
                out.close();
                in.close();
                socket.close();
            }
            ss.close();
        } catch (IOException e) {
             logger.debug("", e);
        }
    }

    public static void main(String[] args) {
        new SingleServer();
//        new SingleClient();
//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException ex) {
//            java.util.logging.Logger.getLogger(SingleServer.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        new SingleClient();
//        new SingleClient();
//        while (true) {            
//            System.out.println("111");
//        }

    }
}
